<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="user.name">
  <input type="text" placeholder="请输入员工工资" v-model="user.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="user.position">
  <button @click="add">添加员工</button>

  <table border="1">
    <tr>
      <th>序号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(item,index) in arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.position}}</td>
    </tr>
  </table>
</template>


<script setup>

import {ref} from "vue";

const user = ref({
  name: '',
  salary: '',
  position: ''
});

const arr = ref([]);

const add = () => {
  if(user.value.name.trim()==''||user.value.salary.trim()==''||user.value.job.trim()==''){
    alert('请输入员工信息!');
    return;
  }
  arr.value.push(user.value);
  user.value = {
    name: '',
    salary: '',
    position: ''
  };
  console.log(arr.value);
}



</script>


<style scoped>

</style>